package com.mm.learn.juc;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author wdx
 * @create 2021-10-18 17:11
 */
public class Test {

    volatile static int x;

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(2);
       /* pool.execute(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            x = 10;
        });
        pool.execute(() -> {
            System.out.println(x);
        });*/
        Future<String> submit = pool.submit(() -> {
            Thread.sleep(3000);
            return "sadsd";
        });
        pool.execute(() -> {
            System.out.println(1);
        });
        System.out.println(submit.get());
        pool.execute(() -> {
            System.out.println(2);
        });
        System.out.println("sadsad");
       /* new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            x = 10;
        },"t1").start();

        new Thread(() -> {
            System.out.println(x);
        },"t2").start();

    }*/
    }

}
